<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="juanQuestionList">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="编码" align="center" prop="questionCode" />
      <el-table-column label="题目类型" align="center" prop="questionType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.topic_type" :value="scope.row.questionType" />
        </template>
      </el-table-column>
      <el-table-column label="难度系数" align="center" prop="questionDifficult">
        <template slot-scope="scope">
          {{ scope.row.questionDifficult | floatFormat }}
        </template>
      </el-table-column>
      <el-table-column label="难易程度" align="center" prop="questionEasy">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.difficulty" :value="scope.row.questionEasy" />
        </template>
      </el-table-column>
      <el-table-column label="重要性" align="center" prop="questionGrade">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.grade" :value="scope.row.questionGrade" />
        </template>
      </el-table-column>
      <el-table-column label="题目内容" align="center" prop="questionContent" min-width="100">
        <template slot-scope="scope">
          <el-button slot="reference" size="small" @click="showHtml(scope.row.questionContent)">查看html</el-button>
        </template>
      </el-table-column>
      <!--      <el-table-column label="创建人" align="center" prop="createdBy" />-->
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getQuestionList } from "@/api/juan/juanQuestion";
import { getToken } from "@/utils/auth";

export default {
  name: "QuestionListTable",
  components: {},
  dicts: ["topic_type", "difficulty", "grade", "capability_level"],
  props: {
    autoLoad: {
      type: Boolean,
      default: true,
    },
    reposId: {
      type: String,
      default: "",
    },
    knowledgeId: {
      type: String,
      default: "",
    },
    courseId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 题目表格数据
      juanQuestionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/juan/juanQuestion/importQuestions",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // courseId: undefined,
        // chapterId: undefined,
        // knowledgeId: undefined,
        questionCode: undefined,
        questionType: undefined,
        questionDifficult: undefined,
        questionEasy: undefined,
        capabilityLevel: undefined,
        questionMajor: undefined,
        questionGrade: undefined,
        questionSubject: undefined,
        questionContent: undefined,
        createdBy: undefined,
        createdTime: undefined,
        updatedBy: undefined,
        updatedTime: undefined,
      },
    };
  },
  created() {
    if (this.autoLoad) {
      this.getList();
    }
  },
  methods: {
    /** 查询题目列表 */
    getList() {
      this.loading = true;
      let options = {
        ...this.queryParams,
        reposId: this.reposId,
        knowledgeId: this.knowledgeId,
      };
      getQuestionList(options).then((response) => {
        this.$nextTick(() => {
          this.juanQuestionList = response.data.rows;
          this.total = response.data.total;
          this.loading = false;
          this.$forceUpdate();
        });
      });
    },
    showHtml(html) {
      this.$alert(html, "题目信息", {
        dangerouslyUseHTMLString: true,
        customClass: "question-html",
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  padding: 0 6px 0 20px;

  .pagination-container {
    margin-bottom: 0;
  }
}
</style>
<style lang="scss">
.question-html {
  width: 1000px;
  .el-message-box__content {
    box-sizing: border-box;
    word-wrap: break-word;
  }
}
</style>
